#ifndef VESA_VESA_H
#define VESA_VESA_H

#include <klibc/ctype.h>
#include <system/mod.h>

#define VBE_DISPI_IOPORT_INDEX			0x01CE
#define VBE_DISPI_IOPORT_DATA			0x01CF
#define VBE_DISPI_INDEX_ID				0x0
#define VBE_DISPI_INDEX_XRES			0x1
#define VBE_DISPI_INDEX_YRES			0x2
#define VBE_DISPI_INDEX_BPP				0x3
#define VBE_DISPI_INDEX_ENABLE			0x4
#define VBE_DISPI_INDEX_BANK			0x5
#define VBE_DISPI_INDEX_VIRT_WIDTH		0x6
#define VBE_DISPI_INDEX_VIRT_HEIGHT		0x7
#define VBE_DISPI_INDEX_X_OFFSET		0x8
#define VBE_DISPI_INDEX_Y_OFFSET		0x9

#define VBE_DISPI_DISABLED				0x00
#define VBE_DISPI_ENABLED				0x01
#define VBE_DISPI_GETCAPS				0x02
#define VBE_DISPI_8BIT_DAC				0x20
#define VBE_DISPI_LFB_ENABLED			0x40
#define VBE_DISPI_NOCLEARMEM			0x80

struct vbeControllerInfo
{
   char signature[4];             // == "VESA"
   short version;                 // == 0x0300 for VBE 3.0
   short oemString[2];            // isa vbeFarPtr
   unsigned char capabilities[4];
   short videomodes[2];           // isa vbeFarPtr
   short totalMemory;             // as # of 64KB blocks
};


extern module_t vesa_module;

void vbe_write(word, word);
void vbe_set(word, word, word);


uint32_t *screenBase;
uint32_t screenX;
uint32_t screenY;
uint32_t screenBpp;

uint32_t vesa_init();
uint32_t vesa_shut(); 
int vesa_init_mode(uint32_t, uint32_t, uint32_t);
void vesa_get_info();
uint32_t vesa_get_x();
uint32_t vesa_get_y();
uint32_t vesa_get_pixel(uint32_t, uint32_t);
void vesa_draw_text8(uint32_t, uint32_t, char *, uint32_t);
void vesa_draw_rect(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); 
void vesa_draw_line(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); 
void vesa_draw_rect_fill(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); 
void vesa_draw_rect_bordered(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); 
void vesa_draw_pixel(uint32_t, uint32_t, uint32_t);

#define VESA_TEXT8_SPACING	2

#endif
